package com.ahzx.aboutus.service.impl;

import com.ahzx.aboutus.domain.AboutUs;
import com.ahzx.aboutus.mapper.AboutUsMapper;
import com.ahzx.aboutus.service.AboutUsService;
import com.ahzx.utils.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 关于我们 业务实现层
 *
 * @Author syg
 * @Date 2021/4/27 9:51
 * @Desc To be or not to be,that is a question.
 */
@Service
public class AboutUsServiceImpl implements AboutUsService {

    @Autowired
    private AboutUsMapper aboutUsMapper;

    @Override
    public List<AboutUs> selectAboutUsInfo() {
        return aboutUsMapper.selectAboutUsInfo();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteAboutUsByKey(Integer id) {
        if (StringUtils.isEmpty(id.toString())) {
            throw new ServiceException("主键不能为空！");
        }
        aboutUsMapper.deleteAboutUsByKey(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertAboutUs(AboutUs aboutUs) {
        if (aboutUsMapper.countAboutUs() > 0) {
            throw new ServiceException("已存在关于我们，请删除后再添加！");
        }
        aboutUsMapper.insertAboutUs(aboutUs);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateAboutUsById(AboutUs aboutUs) {
        if (StringUtils.isEmpty(aboutUs.getId().toString())) {
            throw new ServiceException("主键不能为空！");
        }
        aboutUsMapper.updateAboutUsById(aboutUs);
    }
}
